<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>loadScriptString</title>
</head>

<body>
    <script>
        const loadScriptString = node => {
            const script = document.createElement('script');
            script.type = 'text/javascript';
            try {
                script.appendChild(document.createTextNode(node));
            } catch (ex) {
                script.text = node;
            }
            document.body.appendChild(script);
        }
        loadScriptString("function sayHi(){alert('hi');}");
        // sayHi();
    </script>
</body>

</html>